<?php

/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

require_once dirname(__FILE__)."/Localization.class.php";

class Time
{	
	static private $instance;
	
	private $localization;
	
	private function __construct()
	{
		$this->localization = Localization::GetInstance();
	}
	
	static function GetInstance()
	{
		if ( empty(self::$instance) )
		{
			self::$instance = new Time();
		}
		
		return self::$instance;
	}
	
	function GetLiteralDelayByTimestamp($timestamp)
	{
		$string = null;
		
		if ( time() - $timestamp < 86400 )
		{
			$string .= "&lt; 1 ".$this->localization->Get('day');
		}
		elseif ( time() - $timestamp < 172800 )
		{
			$string .= "&lt; 2 ".$this->localization->Get('days');
		}
		elseif ( time() - $timestamp < 604800 )
		{
			$string .= "&lt; 1 ".$this->localization->Get('week');
		}
		elseif ( time() - $timestamp < 2592000 )
		{
			$string .= "&lt; 1 ".$this->localization->Get('month');
		}
		
		return $string;
	}
	
	function ConvertSecondsToTime($seconds)
	{
		$d = intval($seconds / (3600*24));
		$h = intval(($seconds - $d*3600*24)/3600);
		$m = intval(($seconds - $d*3600*24 - $h*3600)/60);
		
		return $d.$this->localization->Get('d(ays)')." ".$h.$this->localization->Get('h(ours)')." ".$m.$this->localization->Get('m(inutes)')." ";
	}
}

?>